package com.design.pattern.creator.factory.simple;

public class CourseFactory {
    public ICourse create(String name) {
        if ("java".equals(name)) {
            return new JavaCousre();
        } else if ("python".equals(name)) {
            return new PythonCourse();
        }
        return null;
    }

    public ICourse createByClassName(String className) {
        if (null == className) {
            return null;
        }
        ICourse iCourse = null;
        try {
            iCourse = (ICourse) Class.forName(className).newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return iCourse;
    }

    public ICourse create(Class<? extends ICourse> clazz) {
        if(null == clazz) {
            return null;
        }
        try {
            return clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}
